package com.pudding.base;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;

public class HelloWorld {
    public static void main(String[] args) {
        ChatLanguageModel model = OpenAiChatModel.builder()
                .apiKey("demo")
                .modelName("gpt-4o-mini")
                .build();

//        String answer = model.generate("你是谁");
//        System.out.println(answer);
//
//        String answer2 = model.generate("请重复一次");
//        System.out.println(answer2);

        System.out.println("------------------------");

        // 下面保证了在一个会话内，每次调用的会话id相同
        UserMessage userMessage = UserMessage.from("你是谁？");
        Response<AiMessage> response = model.generate(userMessage);
        AiMessage aiMessage = response.content();
        System.out.println(aiMessage.text());

        UserMessage userMessage2 = UserMessage.from("请重复一次");
        Response<AiMessage> response2 = model.generate(userMessage, aiMessage, userMessage2);
        System.out.println(response2.content().text());
    }
}
